import requests
from bs4 import BeautifulSoup

res = requests.get(
    url="https://www.autohome.com.cn/news/",
    headers={
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0",
    }
)
res.encoding = 'gb2312'

# 第1步：将文本交给BeautifulSoup，让他帮我们结构化处理。
soup = BeautifulSoup(res.text, features='html.parser')

# 第2步：根据特点，利用  find  findall 找到相应的标签
part_area = soup.find(name='div', attrs={"id": "auto-channel-lazyload-article"})

# 所有的li标签 = [li,li,li]
li_list_node = part_area.find_all(name='li')
for li_node in li_list_node:
    h3 = li_node.find(name='h3')
    if not h3:
        continue

    print(h3.text)

    # 找到标签，获取他的文本
    p = li_node.find(name='p')
    print(p.text)

    # 找到标签，获取属性  <img src='xxx' />
    img = li_node.find(name='img')
    print(img.attrs['src'])
    print('-----------------')